package com.info.zhiduoduo.common.configs;

import com.info.zhiduoduo.common.utils.RSAUtil;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.util.Map;

import javax.annotation.PostConstruct;

import lombok.Data;

import static com.info.zhiduoduo.common.utils.RSAUtil.PRIVATE_KEY;
import static com.info.zhiduoduo.common.utils.RSAUtil.PUBLIC_KEY;

@Component
@PropertySource(value = "kltpay-${spring.profiles.active}.properties")
@ConfigurationProperties("kltpay")
@Data
@Slf4j
public class KltPayConfig {

	private String jiugeAccountName;
	private String jiugeAccountNo;
	private String jiugeBankName;
	private String jiugeBankNo;

	private String md5Key;
	private String merchantId;
	private String keyFilePath;
	private String companyCAFilePath;

	private String payUrl;
	private String queryUrl;
	private String payNotifyUrl;
	private String withdrawNotifyUrl;
	private String batchPayUrl;
	private String batchQueryUrl;

	private String addMerchantUrl;
	private String queryMerchantUrl;
	private String queryAccountInfoUrl;

	private String offlineCreateOrderUrl;
	private String offlineQueryOrderUrl;
	private String offlinePaymentNotifyUrl;

	private String privateKey;
	private String publicKey;

	@PostConstruct
	public void loadPrivateKey() {
		Map<String, String> map = null;
		try {
			map = RSAUtil.loadKeyByPfxFile(keyFilePath, "123456");
			privateKey = map.get(PRIVATE_KEY);
			publicKey = map.get(PUBLIC_KEY);
		} catch (Exception e) {
			log.error("KltPayConfig loadPrivateKey Exception:" + e.getMessage());
		}
	}
}
